﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Janus.BaseEntitys
{
    public class PaginationDTO
    {
        public PaginationDTO()
        {
            this.CurrentIndex = 1;
            this.PageSize = 50;
            this.IsPaging = true;
        }
        public int CurrentIndex { get; set; }
        public int PageSize { get; set; }
        public int? RowCount { get; set; }
        private string _strSort = "";

        private bool _IsPaging = true;
        public bool IsPaging
        {
            get { return _IsPaging; }
            set { _IsPaging = value; }
        }
        private bool _ReCount = false;

        /// <summary>
        /// 排序字符串，如:ID ASC等
        /// </summary>
        public string StrSort
        {
            set { _strSort = value; }
            get { return _strSort; }
        }

        /// <summary>
        /// 是否需要重新计算总记录
        /// </summary>
        public bool ReCount
        {
            get
            {
                if (!RowCount.HasValue)
                {
                    _ReCount = true;
                }
                else
                { _ReCount = false; }
                return _ReCount;
                //return CurrentIndex > 1;
            }
            set { _ReCount = value; }
        }
        public int PageTotal
        {
            get
            {
                if (RowCount.HasValue)
                    return (int)Math.Ceiling((double)RowCount / (double)PageSize);
                else
                    return 0;
            }
        }
    }
}
